home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 19.zip / BS1 part 19 / how to learn assembler.adf / CH4 / 4_3_4Aascii-dec.asm < prev    next >
Assembly Source File  |  1988-02-25  |  803b  |  29 lines

  1. ;(4.3.4A) ascii-dec
  2. decin:
  3.      clr.l    d1         ; First erase D1
  4.      move.l   #string,a0 ; The string we want to convert
  5.      jsr      decinloop  ; Test subroutine
  6.      nop                 ; Breakpoint here
  7.  
  8. decinloop:
  9.      bsr      digitin    ; Convert digit
  10.      cmp      #10,d0     ; Test, if valid
  11.      bcc      decinok    ; No, then done
  12.      mulu     #10,d1     ; Shift result
  13.      add      d0,d1      ; Insert nibble
  14.      bra      decinloop  ; And continue
  15.  
  16. decinok:
  17.      rts                 ; End of conversion
  18.  
  19. digitin:                 ; Converting the nibble from (A0)
  20.      clr.l    d0         ; Erase D0
  21.      move.b   (a0)+,d0   ; Get digit, increment A0
  22.      sub      #'0',d0    ; Subtract $30
  23.      rts
  24.  
  25. string:  dc.b  '123456'  ; The ASCII decimal string we want to convert
  26.  
  27.      end
  28.  
  29.